package com.edu.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.edu.dao.BaseDao;
import com.edu.dao.UsertagsDao;
import com.edu.entity.Usertags;

public class UsertagsDaoImpl implements UsertagsDao{
	private BaseDao bd1 = new BaseDao();
	@Override
	public List<Usertags> selectUserTags(int userid) {
		ArrayList<Usertags> uclist = new ArrayList();
		Connection conn = bd1.getConn();
		String sql = "SELECT * FROM usertag WHERE userid=?";
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps = conn.prepareStatement(sql);
			ps.setInt(1, userid);
			rs = ps.executeQuery();
			while(rs.next()) {
				Usertags usertags = new Usertags();
				usertags.setTagid(rs.getInt("tagid"));
				usertags.setUserid(rs.getInt("userid"));
				usertags.setTag(rs.getString("tag"));
				uclist.add(usertags);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			bd1.closeAll(conn, ps, rs);
		}
		return uclist;
	}

}
